<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="20">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="联系人姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入联系人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职务名称" prop="jobName">
        <el-input
          v-model="queryParams.jobName"
          placeholder="请输入职务名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
  </el-col>
    <el-col :span="4">
    <el-button type="primary" icon="el-icon-user-solid" size="mini" @click="noApplyList">未审批人员</el-button>
  </el-col>
  </el-row>

    <el-table v-loading="loading" :data="applyList" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" :index="createIndex" />
      <el-table-column label="头像" align="center" prop="headUrl">
       <!-- 图片的显示 -->
                 <template   slot-scope="scope">            
                    <img :src="scope.row.headUrl"  min-width="70px" height="70px" 
                           @click="previewPic(scope.row.headUrl)" />
                 </template>  
      </el-table-column>
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="入会类型" align="center" prop="applyType">
         <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_members_type" :value="scope.row.applyType"/>
        </template>
      </el-table-column>
       
      <el-table-column label="联系人姓名" align="center" prop="name" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="性别" align="center" prop="sex" >
         <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="是否是老会员" align="center" prop="isOld" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_members_status_type" :value="scope.row.isOld"/>
        </template>
      </el-table-column>
      <el-table-column label="申请状态" align="center" prop="applyStatus">
         <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_member_audit_type" :value="scope.row.applyStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <el-switch  v-model="scope.row.status"
                :active-value="0"
                :inactive-value="2"
                @change="handleStatusChange(scope.row)"></el-switch>
        </template>
      </el-table-column>
    </el-table>
      <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    
    <!-- 图片预览   放在表格外面，这是个弹出框-->
      <el-dialog :visible.sync="dialogVisible" :modal="false" title="图片预览" width="50%">
        <img :src="previewpic" alt=""  width="100%" />
        <span slot="footer" class="dialog-footer">
          </span>
       </el-dialog>
  <!-- 图片预览 -->

    <!-- 添加或修改入会申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="协会id" prop="asId">
          <el-input v-model="form.asId" placeholder="请输入协会id" />
        </el-form-item>
        <el-form-item label="创建人id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入创建人id" />
        </el-form-item>
        <el-form-item label="是否是老会员：0不是，1是" prop="isOld">
          <el-input v-model="form.isOld" placeholder="请输入是否是老会员：0不是，1是" />
        </el-form-item>
        <el-form-item label="团体id" prop="groupNameId">
          <el-input v-model="form.groupNameId" placeholder="请输入团体id" />
        </el-form-item>
        <el-form-item label="企业社团名称" prop="firmName">
          <el-input v-model="form.firmName" placeholder="请输入企业社团名称" />
        </el-form-item>
        <el-form-item label="联系人姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入联系人姓名" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="职务名称" prop="jobName">
          <el-input v-model="form.jobName" placeholder="请输入职务名称" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="行业id" prop="tradeId">
          <el-input v-model="form.tradeId" placeholder="请输入行业id" />
        </el-form-item>
        <el-form-item label="行业名称" prop="tradeName">
          <el-input v-model="form.tradeName" placeholder="请输入行业名称" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="自定义字段内容" prop="customField">
          <el-input v-model="form.customField" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="驳回理由" prop="rejectReason">
          <el-input v-model="form.rejectReason" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="抄送人id多个用;分隔" prop="copyIds">
          <el-input v-model="form.copyIds" placeholder="请输入抄送人id多个用;分隔" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="applyOpen" width="70%" append-to-body>
      <el-table v-loading="loading" :data="notApplyList" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" :index="createIndex" />
      <el-table-column label="头像" align="center" prop="headUrl">
       <!-- 图片的显示 -->
                 <template   slot-scope="scope">            
                    <img :src="scope.row.headUrl"  min-width="70px" height="70px" 
                           @click="previewPic(scope.row.headUrl)" />
                 </template>  
      </el-table-column>
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="入会类型" align="center" prop="applyType">
         <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_members_type" :value="scope.row.applyType"/>
        </template>
      </el-table-column>
       
      <el-table-column label="联系人姓名" align="center" prop="name" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="性别" align="center" prop="sex" >
         <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="是否是老会员" align="center" prop="isOld" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_members_status_type" :value="scope.row.isOld"/>
        </template>
      </el-table-column>
      <el-table-column label="申请状态" align="center" prop="applyStatus">
         <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_member_audit_type" :value="scope.row.applyStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="审核入会" align="center" prop="status" >
        <template slot-scope="scope">
        <el-button type="danger" size="small" plain icon="el-icon-check" @click="updateApplyStatus(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
      <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="noApplyList"
    />
    </el-dialog>
  </div>
</template>

<script>
import { listApply, getApply, delApply, addApply, updateApply,changeNoticeStatus,updateApplyStatu } from "@/api/members/apply";

export default {
  name: "Apply",
   dicts: ['sys_member_audit_type','sys_members_type','sys_members_status_type','sys_user_sex'],
  data() {
    return {
      dialogVisible: false,
        previewpic: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入会申请表格数据
      applyList: [],
      notApplyList:[],
      applyOpen:false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        asId: null,
        userId: null,
        isOld: null,
        groupNameId: null,
        firmName: null,
        applyType: 1,
        name: null,
        phone: null,
        jobName: null,
        sex: null,
        address: null,
        tradeId: null,
        tradeName: null,
        email: null,
        customField: null,
        applyStatus: 1,
        rejectReason: null,
        copyIds: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        asId: [
          { required: true, message: "协会id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //未审批人审核
    updateApplyStatus(row){
        let text = "允许";
      this.$modal.confirm('确认要"' + text + '""' + row.name + '"入会吗？').then(function() {
        return updateApplyStatu(row.id);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
      });
      },

  //未审批人员表格
  noApplyList(){
    this.queryParams.applyStatus=0;
    listApply(this.queryParams).then(res=>{
      this.notApplyList=res.rows;
      this.total=res.total;
      this.loading=false;
      this.applyOpen=true;
      this.title="未审批人员列表"
    })
  },

  //图片放大
      previewPic(url) {
           this.previewpic = url;
           this.dialogVisible = true;
        },
    createIndex(index){
      return (this.queryParams.pageNum - 1)* this.queryParams.pageSize + index + 1;
    },
    /** 查询入会申请列表 */
    getList() {
      this.loading = true;
      listApply(this.queryParams).then(res => {

        this.applyList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
      // 状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.id + '"公告吗？').then(function() {
        return changeNoticeStatus(row.id, row.status);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === "0" ? "2" : "0";
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        asId: null,
        userId: null,
        isOld: null,
        groupNameId: null,
        firmName: null,
        applyType: null,
        name: null,
        phone: null,
        jobName: null,
        sex: null,
        address: null,
        tradeId: null,
        tradeName: null,
        email: null,
        customField: null,
        applyStatus: 0,
        rejectReason: null,
        copyIds: null,
        createTime: null,
        updateTime: null,
        status: 0
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加入会申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getApply(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改入会申请";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateApply(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApply(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除入会申请编号为"' + ids + '"的数据项？').then(function() {
        return delApply(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('members/apply/export', {
        ...this.queryParams
      }, `apply_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
